# -*- coding: utf-8 -*-
# @Time    : 2022/5/24 16:24
# @Author  : liuzehai~
# @Email   : 1129309473@qq.com
# @File    : sales_duobaoqibing_page.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from page.page_font_login import LoginPage
from selenium import webdriver
from time import sleep
from page.base_page import BasePage
class AddredBao(BasePage):
    # def __init__(self, driver):
    #     self.driver = driver
    def cuxi(self):
    # 操作方法
        self.driver.find_element(By.CSS_SELECTOR, "#menu-ul > li.collapse.lis.ico_2").click()
        sleep(3)

    def redbao(self):
        # 红包类型
        self.driver.find_element(By.XPATH, "//*[@id='menu-ul']/li[2]/ul/li[2]/a").click()
        #退出菜单的frame
        self.driver.switch_to.parent_frame()
        # 切入主界面的frame
        self.driver.switch_to.frame("main-frame")
    def addhongbao(self):
        self.driver.find_element(By.XPATH,"/html/body/h1/span[1]/a").click()
        sleep(3)
        # 输入名称
    def input_minchen(self):
        self.driver.find_element(By.XPATH, "/html/body/div[1]/form/table/tbody/tr[1]/td[2]/input").send_keys("红包")
        # 输入金额
    def input_jiner(self):
        self.driver.find_element(By.XPATH, "/html/body/div[1]/form/table/tbody/tr[2]/td[2]/input").send_keys("30")
        sleep(3)
    def click_sure(self):
        # 确定添加
        self.driver.find_element(By.XPATH,"/html/body/div[1]/form/table/tbody/tr[10]/td[2]/input[1]")
    #去前台验证是否添加成功并成功使用
    def get_page(self):
        self.driver.get("http://192.168.4.54:8081/upload/")
    #输入搜索内容
    def input_keys(self):
        self.driver.find_element(By.XPATH, "//*[@id='keyword']").send_keys("毛衣外套")

    #点击搜索
    def search_btn(self):
        self.driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/form/span[2]").click()

    #点击搜索的商品
    def photo(self):
        self.driver.find_element(By.XPATH, "//*[@id='compareForm']/div/div/a/img").click()
    ##点击立即购买
    def ecs_formbuy(self):
        self.driver.find_element(By.XPATH,"//*[@id='ECS_FORMBUY']/ul[3]/li[2]/a/img").click()
    #点击购物中心
    def center_buy(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.block.table > div.flowBox > table > tbody > tr > td:nth-child(2) > a > img").click()
    sleep(4)
    #登录
    def lg_user(self):
        self.driver.find_element(By.XPATH,"//*[@id='username']").send_keys("lwx")
        self.driver.find_element(By.XPATH, "//*[@id='loginForm']/table/tbody/tr[2]/td[2]/input").send_keys("123456")
        self.driver.find_element(By.XPATH,"//*[@id='loginForm']/table/tbody/tr[5]/td/div/input[1]").click()
    def use_redbao(self):
        self.driver.find_element(By.CSS_SELECTOR,"#ECS_BONUS").send_keys("红包[￥222.00元]")

    def submit_buy(self):
        self.driver.find_element(By.CSS_SELECTOR,"#theForm > div:nth-child(14) > div:nth-child(3) > input[type=image]:nth-child(1)").click()
        sleep(5)
    #汇总
    def adredbao(self):
        self.cuxi()
        self.redbao()
        self.addhongbao()
        self.input_minchen()
        self.input_jiner()
        self.click_sure()
        self.get_page()
        self.input_keys()
        self.search_btn()
        self.photo()
        sleep(3)
        self.ecs_formbuy()
        sleep(3)
        self.center_buy()
        sleep(3)
        self.lg_user()
        sleep(5)
        self.use_redbao()
        sleep(5)
        self.submit_buy()
        sleep(3)